#! /usr/bin/env python
# -*- coding: utf-8 -*-
from typing import Literal

from playwright.sync_api import Page

from common.base_page import BasePage
from common.logger import logger
from locators.majorHazardSourceSafety.olMonitorWarn.realtimeWarn.loc_check_deal import LocCheckDeal
from locators.majorHazardSourceSafety.olMonitorWarn.realtimeWarn.loc_query import LocQuery


class RealtimeWarn(BasePage):

    def __init__(self, page: Page):
        super().__init__(page)
        self.switch_menu('重大危险源安全管理')
        self.switch_menu('在线监测预警')
        self.switch_menu('实时预警')

    def query_total_list(self, warn_type, warn_level, company_name, warn_number, warn_name, warn_status, deal_status,
                         start_time, end_time):
        """
        列表查询
        :param warn_type:
        :param warn_level:
        :param company_name:
        :param warn_number:
        :param warn_name:
        :param warn_status:
        :param deal_status:
        :param start_time:
        :param end_time:
        :return:
        """
        logger.info('开始实时监测查询测试')
        logger.info('选择预警类型')
        self.select(LocQuery.loc_warn_type, warn_type)
        logger.info('选择预警等级')
        self.select(LocQuery.loc_warn_level, warn_level)
        logger.info('选择企业名称')
        self.select(LocQuery.loc_company_name, company_name)
        logger.info('输入预警编号')
        self.fill(LocQuery.loc_warn_number, warn_number)
        logger.info('输入预警名称')
        self.fill(LocQuery.loc_warn_name, warn_name)
        logger.info('选择预警状态')
        self.select(LocQuery.loc_warn_status, warn_status)
        logger.info('选择处置状态')
        self.select(LocQuery.loc_deal_status, deal_status)
        logger.info('输入预警时间')
        self.fill_date_time(LocQuery.loc_warn_time, start_time, end_time)
        self.click(LocQuery.loc_query, exact=True)

    def reset(self):
        """
        测试重置
        :return:
        """
        self.click(LocQuery.loc_reset, exact=True)

    def check_warn(self, check_comment):
        """
        核查预警
        :param check_comment: 核查内容
        :return:
        """
        logger.info('开始预警核查测试')
        logger.info('选择预警并点击核查按钮')
        self.click(LocCheckDeal.loc_check_button)
        logger.info('输入核查内容')
        self.fill(LocCheckDeal.log_check_input, check_comment)
        logger.info('点击发送按钮')
        self.click(LocCheckDeal.loc_sumit_button_check)

    def deal_warn(self, deal_comment):
        """
        处置预警
        :param deal_comment: 处置内容
        :return:
        """
        logger.info('开始预警处置测试')
        logger.info('选择预警并点击处置按钮')
        self.click(LocCheckDeal.loc_deal_button)
        logger.info('输入处置内容')
        self.fill(LocCheckDeal.log_deal_input, deal_comment)
        logger.info('点击发送按钮')
        self.click(LocCheckDeal.loc_sumit_button_deal)

    def export(self, export_type: Literal['all', 'part'], value_selected=None):
        logger.info('测试导出功能')
        if export_type == 'all':
            logger.info('直接点击导出按钮')
            res = self.export_and_download(LocCheckDeal.loc_export_button, file_type='excel')
        else:
            logger.info('勾选第一行')
            self.select_row_checkbox(value_selected)
            logger.info('导出数据')
            res = self.export_and_download(LocCheckDeal.loc_export_button, file_type='excel')
        return res
